// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Mp3EntityFactory.cs" company="GT">
//   Gunther Taborga
// </copyright>
// <summary>
//   Defines the Mp3EntityFactory type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

// TODO refactored=false
// TODO introduce logging using log4net or similar technology
namespace BatchID3.Mp3
{
    using System;

    using TagLib;

    public class Mp3EntityFactory : IMp3EntityFactory
    {
        private readonly IMp3FileSystemManager mp3FileSystemManager;

        public Mp3EntityFactory(IMp3FileSystemManager mp3FileSystemManager)
        {
            this.mp3FileSystemManager = mp3FileSystemManager;
        }

        public IMp3Entity CreateMp3Entity(string mp3FilePath)
        {
            try
            {
                return this.CreateInstance(mp3FilePath);
            }
            catch (CorruptFileException)
            {
                Console.WriteLine("Corrupt file found: {0}", mp3FilePath);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error getting tag info from \"{0}\". Exception: {1}", mp3FilePath, e);
            }

            return null;
        }

        private IMp3Entity CreateInstance(string mp3FilePath)
        {
            return new Mp3Entity(this.mp3FileSystemManager, mp3FilePath);
        }
    }
}